package com.stupro.cjlu.controller;


import com.stupro.cjlu.common.utils.VOToEntity;
import com.stupro.cjlu.common.vo.ResultVO;
import com.stupro.cjlu.common.vo.StudentItemVO;
import com.stupro.cjlu.common.vo.TeacherVO;
import com.stupro.cjlu.config.themis.annotation.Student;
import com.stupro.cjlu.entity.Students;
import com.stupro.cjlu.entity.Teacher;
import com.stupro.cjlu.service.AdmainService;
import com.stupro.cjlu.service.CourseService;
import com.stupro.cjlu.service.StudentsService;
import com.stupro.cjlu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2021-05-10
 */
@RestController()
@RequestMapping("/admin")
public class AdmainController extends BaseController {

    @Autowired
    private AdmainService admainService;

    @Autowired
    private StudentsService studentsService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private VOToEntity voToEntity;

//    @GetMapping("/getAllStudentInfo")
//    public ResultVO getAllStudentInfo(Integer page){
////        studentsService.get(page);
//        return result(studentsService.getPage(page,null,null));
//    }

    @GetMapping("/getStudentInfo")
    public ResultVO getStudentInfoByName(Integer page,String name,String claName){
        return studentsService.getPage(page,claName,name);
    }

    @GetMapping("/getGrade")
    public ResultVO getGrade(Integer page,String name,String claName,String courseName){
        return studentsService.getCourse(page, name, claName, courseName);
    }

    @GetMapping("/getTeacher")
    public ResultVO getTeacher(Integer page,String name){
        return teacherService.getTeacher(page,name);
    }

    @GetMapping("/getCourse")
    public ResultVO getdCourse(Integer page,String teacherName,String className){
        return teacherService.getCourse(page,teacherName,className);
    }

    @GetMapping("/delTeacherByTeacherId")
    public ResultVO delTeacher(int id){
        return teacherService.delById(id);
    }

    @GetMapping("/delCourseByCourseId")
    public ResultVO delCourseByCourseId(int id){
        return courseService.delCourseByCourseId(id);
    }

    @PostMapping("/updateTeacher")
    public ResultVO updateTeacher(@RequestBody TeacherVO teacherVO){
        Teacher teacher = voToEntity.toTeacher(teacherVO);
        return teacherService.update(teacher);
    }

    @PostMapping("/updateStudent")
    public ResultVO updateStudent(@RequestBody StudentItemVO studentVO){
        Students student = voToEntity.toStudent(studentVO);
        return studentsService.update(student);
    }


}
